<template class="template">
  <div class="root">
    <wux-toptips id="wux-toptips" />
    <div class="top-container">
      <div class="top_background">
        <div>
          <div class="user-info" v-if="showUserInfo === true">
            <img :src="user.avatarUrl" class="head_portrait" />
            <span class="background_title">
              {{ user.nickName }}
              <div class="vip-icon" v-if="user.memberLevel != 0">
                <i class="iconfont icon-VIP2 vip"></i>
              </div>
            </span>
            <!-- <div class="become-vip" v-if="user.memberLevel == 0" @click="becomeVip">开通会员</div> -->
            <div v-if="user.memberLevel == 0">
              <div class="equity">
                <span class="line"></span>
                <span class="text">
                  会员专享
                  <span class="special">5</span> 大权益
                </span>
                <span class="line"></span>
              </div>
              <div class="equity-full">
                <div class="equity-item" v-for="(item, key) in equitys" :key="key">
                  <div :class="'iconfont ' + item.icon"></div>
                  <div class="equity-item-title">{{ item.title }}</div>
                  <div class="equity-item-info">{{ item.info }}</div>
                </div>
              </div>
            </div>
            <div class="user-card-number" v-else>
              <div>{{ user.cardNumber }}</div>
              <!-- <div>有效期至: {{ endTime }}</div> -->
            </div>
          </div>
          <div class="user-info" v-else>
            <img class="head_portrait" src="../../static/images/user.png" />
            <span @click="login" class="background_unlogin">登录/注册</span>
          </div>
        </div>
        <!-- <wux-button v-else class="login-btn" type="calm" @click="login"
          >点击登录</wux-button
        >-->
      </div>
    </div>
    <div class="link_title_outer">
      <div class="btn_list_outer">
        <ul class="btn_list">
          <li v-for="(i, index) in models" :key="index" v-on:click="transaction(index)">
            <i :class="'iconfont icon-' + i.icon"></i>
            <span>{{ i.value }}</span>
          </li>
        </ul>
      </div>
      <ul class="link_title">
        <!-- <li @click="closed">我的关注</li> -->
        <li @click="closed">完善信息</li>
        <li @click="toAboutus">联系我们</li>
        <li>
          <button class="open-custom" open-type="contact">在线客服</button>
        </li>
        <!-- <li v-if="showAcceptSubscriptButton" @click="onSubscriput">订阅消息授权</li> -->
      </ul>
    </div>
    <div class="coryright">@ 卡卡伴旅</div>
  </div>
</template>

<script>
// import { formatTime } from '@/utils/index'
// import card from '@/components/card'

import { $wuxToptips } from "../../static/wux/index";

export default {
  // components: {
  //   card
  // },
  data() {
    return {
      models: [
        { icon: "order", value: "交易明細" },
        { icon: "zulindingdan", value: "租赁订单" },
        { icon: "xianqulingshi", value: "常见问题" },
      ],
      flag: 0,
      value: "",
      showUserInfo: false,
      endTime: "",
      equitys: [
        {
          icon: "icon-free",
          title: "会员租赁",
          info: "限时免租金",
        },
        {
          icon: "icon-quan",
          title: "超值神券",
          info: "88元/月",
        },
        {
          icon: "icon-quanyiguanli-",
          title: "卡卡会员",
          info: "精选99+商品",
        },
        {
          icon: "icon-Fill",
          title: "客房服务",
          info: "尊享客房服务",
        },
        {
          icon: "icon-kefu",
          title: "专属客服",
          info: "极速专线",
        },
      ],
    };
  },
  computed: {
    user() {
      let newUser = this.$store.state.user;
      if (newUser.nickName !== undefined) {
        this.showUserInfo = true;
        this.getYearMonth(newUser.endTime);
        return newUser;
      }
      return newUser;
    },
  },
  onShow() {
    if (this.$store.state.cart.length === 0) {
      wx.removeTabBarBadge({
        index: 2,
      });
    } else {
      wx.setTabBarBadge({
        index: 2,
        text: this.$store.state.cart.length + "",
      });
    }
  },
  created() {
    wx.showShareMenu();
    if (this.user.nickName !== undefined) {
      this.showUserInfo = true;
      // this.$router.push({ path: "/pages/login" });
    }
  },
  // mounted() {
  //   let that = this;
  //   wx.getSetting({
  //     withSubscriptions: true,
  //     success(res) {
  //       console.log(res);
  //       var itemSettings = res.subscriptionsSetting.itemSettings;
  //       if (itemSettings) {
  //         if (
  //           itemSettings["Liybyf6Oik96Wgr3DPgxX6DZENh5oK9twbJtHYSsZ3I"] ===
  //           "accept"
  //         ) {
  //           that.showAcceptSubscriptButton = false;
  //         }
  //       }
  //     }
  //   });
  // },
  methods: {
    // onSubscriput() {
    //   wx.requestSubscribeMessage({
    //     tmplIds: ["Liybyf6Oik96Wgr3DPgxX6DZENh5oK9twbJtHYSsZ3I"],
    //     success(res) {
    //       console.log(res);
    //     }
    //   });
    // },
    getYearMonth(date) {
      // 将日期以空格隔开，即['2020-06-13', '17:10:09']
      date = (date + "").split(/[ ]+/);
      let result = [];
      let reg = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;
      // 用截取出来的年月日进行正则表达式匹配
      reg.exec(date[0]);
      result.push(RegExp.$1);
      result.push(RegExp.$2);
      result.push(RegExp.$3);
      this.endTime = result.join("-");
    },
    login: function () {
      this.$router.push({ path: "/pages/login" });
    },
    becomeVip() {
      this.$router.push({ path: "/pages/memberDetail" });
    },
    transaction: function (index) {
      if (index === 0) {
        this.$router.push({ path: "/pages/transaction" });
      } else if (index === 1) {
        this.$router.push({ path: "/pages/myLeaseList" });
      } else if (index === 2) {
        this.$router.push({ path: "/pages/help" });
      }
    },
    toAboutus: function () {
      this.$router.push({ path: "/pages/about" });
    },
    closed: function () {
      $wuxToptips().warn({
        hidden: false,
        text: "该功能暂未开放!",
        duration: 1000,
        success() {},
      });
    }
  },
};
</script>

<style scoped lang="less">
.root {
  height: 100vh;
  background: #f3f3f3;
  .top-container {
    background-color: #f3f3f3;
    padding: 40px 15px 0 15px;
    .top_background {
      padding: 20px;
      height: 150px;
      position: relative;
      // background: url(http://erp.0511mzone.com/upload/centerBg.jpg) no-repeat;
      // background-size: 100% 100%;
      // background-color: #3d3d3d;
      background: url(../../static/images/center-btn.gif);
      border-radius: 20px 20px 0 0;
      .user-info {
        .background_title {
          font-size: 15px;
          margin-left: 20px;
          font-weight: bolder;
          color: #fafad2;
        }
        .become-vip {
          border: 2rpx solid #fafad2;
          margin-left: 4rpx;
          font-size: 26rpx;
          border-radius: 10px;
          padding: 10rpx;
          color: #736e6e;
          background-color: #fafad2;
          float: right;
        }
        .background_unlogin {
          font-size: 15px;
          margin-left: 20px;
          font-weight: bolder;
          color: #ffffff;
        }
        .head_portrait {
          width: 40px;
          height: 40px;
          border-radius: 100%;
          color: #efefef;
          border: 2px solid #efefef;
          vertical-align: middle;
        }
      }
      .vip-icon {
        float: right;
        .vip {
          font-size: 30px;
          color: #D9D919;
        }
      }
      .equity {
        text-align: center;
        font-weight: bolder;
        margin: 20rpx 0;
        .text {
          color: #fafad2;
          vertical-align: middle;
          margin: 0 25px;
          .special {
            font-size: 25px;
            margin: 0 3px;
          }
        }
        .line {
          display: inline-block;
          width: 15%;
          border: 1px solid #ddd;
          border-image: -webkit-linear-gradient(#fafad2, white, #fafad2) 1 10 1; /* 控制边框颜色渐变 */
          border-image: -moz-linear-gradient(#fafad2, white, #fafad2) 1 10 1;
          border-image: linear-gradient(#fafad2, white, #fafad2) 1 10 1; /* 标准的必须写在最后 */
        }
      }

      .equity-full {
        display: flex;
        .equity-item {
          flex: 1;
          text-align: center;
          margin: 0 5px;
          .iconfont {
            font-size: 24px;
            color: #fafad2;
          }
          .equity-item-title {
            margin: 5px 0 2px 0;
            color: #fafad2;
            font-size: 10px;
          }
          .equity-item-info {
            color: #daa520;
            font-size: 8px;
          }
        }
      }

      .user-card-number {
        font-family: menlo, tahoma;
        color: #fafad2;
        margin: 40px 0 0 10px;
        font-size: 20px;
        letter-spacing: 5px;
        text-align: center;
        text-shadow: 1px 1px 2px #666;
        div {
          padding: 7px 0;
        }
      }
    }
  }
  .link_title_outer {
    background: #fff;
    .btn_list_outer {
      box-shadow: 0 0 15rpx 5rpx #cccccc;
      .btn_list {
        display: flex;
        background: #fff;
        padding: 10px 0;
        li {
          width: 50%;
          text-align: center;
          font-weight: 200;
        }
        span {
          padding-top: 10px;
          display: block;
          font-size: 13px;
        }
      }
    }
    .link_title {
      li {
        display: block;
        padding: 20px;
        display: block;
        position: relative;
        &:after {
          content: " ";
          position: absolute;
          bottom: 0;
          height: 1px;
          background-color: #efefef;
          left: 0;
          width: 100%;
        }
        button {
          background-color: transparent;
          padding-left: 0;
          padding-right: 0;
          border-radius: 0;
          display: inline-block;
          text-align: left;
          font-size: 14px;
          line-height: inherit;
          width: 100%;
          &:after {
            border: none;
          }
        }
      }
    }
  }
  .coryright {
    text-align: center;
    color: #999999;
    font-size: 12px;
    padding: 10px;
  }
}
</style>

